package yuejian_07.yuejian_07.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;

import yuejian_07.yuejian_07.R;
import yuejian_07.yuejian_07.RetrofitListener;
import yuejian_07.yuejian_07.javabean.Contest;
import yuejian_07.yuejian_07.model.ContestModel;




public class ConInfoActivity extends Activity implements RetrofitListener<Contest> {

    TextView c_name,address,date,price,man_count,phone,intro;
    ImageView img_return,img_collect,pic;
    Button enroll;
    //private int user_id;
    private int contest_id;
    private String contest_name;
    private String contest_pic;
    private String contest_intro;
    private String contest_regist_time;
    private int contest_phone;
    private Contest contest;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
        setContentView(R.layout.activity_con_info);
        initViews();
        initEvents();
        initData();
    }

    public void initViews(){
        c_name=(TextView)findViewById(R.id.contest_name);
        address=(TextView)findViewById(R.id.address);
        date=(TextView)findViewById(R.id.date);
        price=(TextView)findViewById(R.id.price);
        man_count=(TextView)findViewById(R.id.man_count);
        phone=(TextView)findViewById(R.id.phone);
        intro=(TextView)findViewById(R.id.info);
        img_return=(ImageView) findViewById(R.id.img_return);
        img_collect=(ImageView) findViewById(R.id.collect);
        pic=(ImageView) findViewById(R.id.pic);
        enroll=(Button) findViewById(R.id.enroll);
    }

    public void initEvents(){

        img_return.setOnClickListener(new View.OnClickListener() {//返回
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        img_collect.setOnClickListener(new View.OnClickListener() {//收藏
            @Override
            public void onClick(View v) {
                //collectActivity();
            }
        });



    }

    public void initData(){

        getActivityInfo();
        //getUserId();
        //checkCollect();

    }

    //获取菜品信息数据
    public void getActivityInfo(){

        Bundle bundle = getIntent().getExtras();
        contest_id = bundle.getInt("contest_id");
        ContestModel contestModel = new ContestModel();
        contestModel.getContestById(contest_id,this);

    }
    @Override
    public void onSuccess(Contest contest){
        contest_name = contest.getContest_name();
        contest_pic ="http://10.0.2.2/neu1_yuejian/Public/Admin/photo/"+contest.getContest_pic();
        contest_intro=contest.getContest_intro();
        contest_regist_time=contest.getContest_regist_time();
        contest_phone=contest.getContest_phone();
        c_name.setText(contest_name);
        intro.setText(contest_intro);
        date.setText(contest_regist_time);

        if (contest_pic != "") {
            Picasso.with(ConInfoActivity.this)
                    .load(contest_pic)
                    .into(pic);
            pic.setScaleType(ImageView.ScaleType.FIT_XY);
        } else {
            pic.setImageResource(R.drawable.no_pic);
        }

    }
    @Override
    public void onFail(){ Toast.makeText(ConInfoActivity.this, "网络发生错误", Toast.LENGTH_SHORT).show();}

    //获取个人用户信息
    /*public void getUserId(){
        SharedPreferences sharedPreferences = getSharedPreferences("userInfo", Context.MODE_PRIVATE);
        user_id = sharedPreferences.getInt("user_id", 0);
    }*/

}

